package com.niit.controller;

import com.niit.bean.R;
import com.niit.entity.Product;
import com.niit.service.ProductService;
import com.niit.service.impl.StaticAndRecProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"商品信息接口"})
@RestController
@RequestMapping("/rec/product")
@CrossOrigin
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private StaticAndRecProductService staticAndRecProductService;

    @ApiOperation(value = "获取所有商品")
    @GetMapping("getProductList")
    public R getProductList(){
        return productService.getProductList();
    }

    @ApiOperation(value = "根据id获取某件商品")
    @GetMapping("getProductById/{id}")
    public R getProductById(@PathVariable Integer id){
        return productService.getProductById(id);
    }

    @ApiOperation(value = "增加新的商品")
    @PostMapping("addNewProduct")
    public R addNewProduct(@RequestBody Product product){
        return productService.addNewProduct(product);
    }

    @ApiOperation(value = "更新商品")
    @PutMapping("updateProduct")
    public R updateProductById(@RequestBody Product product){
        return productService.updateProduct(product);
    }

    @ApiOperation(value = "根据ID删除商品")
    @DeleteMapping("deleteById/{id}")
    public R deleteById(@PathVariable Integer id){
        return productService.deleteProduct(id);
    }

    @ApiOperation(value = "获取评分次数最多的商品")
    @GetMapping("getRateMoreProductList")
    public R getRateMoreProductList(){
        return staticAndRecProductService.getRateMoreProductList();
    }

    @ApiOperation(value = "获取最近评分最多的商品")
    @GetMapping("getRecentlyRateMoreProductList")
    public R getRecentlyRateMoreProductList(){
        return staticAndRecProductService.getRecentlyRateMoreProductList();
    }

    @ApiOperation(value = "获取离线计算得到的用户商品推荐列表")
    @GetMapping("getOfflineUserRecs/{userId}")
    public R getOfflineUserRecs(@PathVariable Integer userId){
        return staticAndRecProductService.getOfflineRecs(userId);
    }

    @ApiOperation(value = "获取实时计算得到的用户商品推荐列表")
    @GetMapping("getRealtimeUserRecs/{userId}")
    public R getRealtimeUserRecs(@PathVariable Integer userId){
        return staticAndRecProductService.getRealtimeRecs(userId);
    }
}
